package com.three.Controller;

import com.github.pagehelper.PageInfo;
import com.three.Pojo.Dorm;
import com.three.Service.IDormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/dorm")
public class DormController {
    @Autowired
    private IDormService dormService;
    @RequestMapping("/todorm.do")
    public String todorm(ModelMap map, String dormName,
                         @RequestParam(defaultValue = "1") Integer pageNum,
                         @RequestParam(defaultValue = "5") Integer pageSize){
        PageInfo<Dorm> pagelist=dormService.findlist(pageNum,pageSize,dormName);
        map.addAttribute("pagelist",pagelist);
        map.addAttribute("dormName",dormName);
        return "Dorm";
    }

    @RequestMapping("/toadd.do")
    public String toadd(){
        return "DormAdd";
    }

    @RequestMapping("/addsave.do")
    public  String addsave(Dorm dorm){
        dormService.addsave(dorm);
        return "redirect:/dorm/todorm.do";

    }
    @RequestMapping("/promodify.do")
    public  String promodify(ModelMap map,Integer Id){
       Dorm dorm=dormService.findByid(Id);
       map.addAttribute("dorm",dorm);
        return "DormUpdate";
    }

    @RequestMapping("/updatesave.do")
    public  String updatesave(Dorm dorm){
        dormService.updatesave(dorm);
        return "redirect:/dorm/todorm.do";
    }

    @RequestMapping("/delete.do")
    public  String delete(Integer Id){
        dormService.delte(Id);
        return "redirect:/dorm/todorm.do";

    }


}
